import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
import java.net.*;
import java.rmi.*;

public class sendBut implements ActionListener,ClientInterface,passwordInterface {
			
			static int t = 1;
			//static String ra = null;
			//static int top = 0;
			//int ttop = Integer.parseInt(lab6.getText());
			//public sendBut() 
			//{
			 	
		//	}
			
			
			public void actionPerformed(ActionEvent e) {
		             //ttop.setText(lab6.getText());
			     //ra = ttop.getText();
			     //top = Integer.parseInt(ra);
		             String filepath = taf1.getText();
		             if(filepath.equals("")) 
		             JOptionPane.showMessageDialog(null,"Error..","Error",JOptionPane.ERROR_MESSAGE);
		             else {
		             File afile = new File(filepath);
		             
					
					if(t >= Integer.parseInt(lab6.getText())) 
				{
					bt1.setEnabled(false);
					bt2.setEnabled(false);
				}	
		try
			{
				int size = (int)afile.length();
				int char_reads = 0;
				FileReader in = new FileReader(afile);
				char data[] = new char[size];
				while(in.ready())
				{
					char_reads += in.read(data,char_reads,size-char_reads);
				}
				in.close();
				String ra = new String(data,0,char_reads);
				taxnull.setText(ra);		
			}
			catch(IOException ioe)
			{
				JOptionPane.showMessageDialog(null,"Error Openning the file","Error",JOptionPane.ERROR_MESSAGE);
			}
		try
		{
			String addServerUrl = "rmi://"+clientconf.getText()+"/MainServer" ;
			MainServerInterface se = (MainServerInterface)Naming.lookup(addServerUrl);
			
			String ra5 = se.AnsTransfer((taxnull.getText()),(usersName.getText()));
			if(ra5.equals("hollo")) 
			{
			t++;	
					
			}
			//System.out.println(ra5);
							
		}
		catch(Exception ex)
		{
			System.out.println("Error Occured at the initialing server Object");
			ex.printStackTrace();
		}
	
		}	
	}
}
